<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Team extends MY_Main {

	/**
	 * Index Page for this controller.
	 *
	 * Maps to the following URL
	 * 		http://example.com/index.php/welcome
	 *	- or -  
	 * 		http://example.com/index.php/welcome/index
	 *	- or -
	 * Since this controller is set as the default controller in 
	 * config/routes.php, it's displayed at http://example.com/
	 *
	 * So any other public methods not prefixed with an underscore will
	 * map to /index.php/welcome/<method_name>
	 * @see http://codeigniter.com/user_guide/general/urls.html
	 */
	public function index()
	{		
		$this->load->view('template/header');
		$this->load->view('team/main');
		//$this->load->view('template/footer');
	}
	
	public function createTeam(){
		$data["title"]  = "Add Team";
		$data["action"] = "add";
		
		$this->load->view('template/header');
		$this->load->view('team/form',$data);
		$this->load->view('template/footer');
	}
	
		
	public function doCreate(){
		$this->load->model ('master/teams','team');
			
			$team_logo = '/uploads/teams/'.$_POST["userfile_filename"];
			$team_name = $_POST['team_name'];
			$team_country = $_POST['team_country'];
			$team_type = $_POST['team_type'];
			$team_enabled = isset($_POST['team_enabled'])?$_POST['team_enabled']:0;
				
			$this->team->create_team($team_logo,$team_name,$team_country,$team_type,$team_enabled);				
		
			
	}
	
	public function editTeam(){
		$this->load->model ('master/teams','team');
		
		$teamid = $_GET['teamid'];
							
		$data["team"] = $this->team->get_team($teamid);
		//$data["companyid"] = $companyid;
		$data["title"]  = "Edit Team";
		$data["action"] = "edit";
		
		$this->load->view('template/header');
		$this->load->view('team/form',$data);
		$this->load->view('template/footer');
	}
	
	public function doEdit(){
		$this->load->model ('master/teams','team');
	
		if(isset($_POST["userfile_filename"]) && $_POST["userfile_filename"] != ""){
			$team_logo = '/uploads/teams/'.$_POST["userfile_filename"];
		}else{
			$team_logo = $_POST['team_logo'];
		}
		
		$teamid = $_POST['team_id'];
		$team_name = $_POST['team_name'];
		$team_country = $_POST['team_country'];
		$team_type = $_POST['team_type'];
		$team_enabled = isset($_POST['team_enabled'])?$_POST['team_enabled']:0;
		$this->team->edit_team($teamid,$team_logo,$team_name,$team_country,$team_type,$team_enabled);
				
	}
	
	public function doDelete(){
		$this->load->model ('master/teams','team');
	
		$teamid = $_POST['teamid'];
		$this->team->delete_team($teamid);
	
	}
	
	
	public function getallteam(){
	
		$this->load->model ('master/teams','team');
		
		$data = $this->team->getAllTeam();
	
		header("Content-type: application/json");
		echo "{\"data\":" .json_encode($data). "}";
		
	}
	
}